package org.hackystat.ambientdevice.device.orb;

import java.io.Serializable;
import org.hackystat.ambientdevice.ConfigurationException;
import org.hackystat.ambientdevice.device.AmbientAction;
import org.hackystat.ambientdevice.device.orb.AmbientOrb.Color;

/**
 * Class that implement AmbientAction to change the AmbientOrb's Color.
 * 
 * @author Shaoxuan Zhang
 */
public class ChangeColor implements AmbientAction, Serializable {

  /**
   * default serial.
   */
  private static final long serialVersionUID = 1L;
  /** the AmbientOrb that will change Animation. */
  private AmbientOrb orb;
  /** the Animation it will be. */
  private Color color = null;

  /** The logger for logging. */

  /**
   * Constructor.
   * 
   * @param orb an AmbientOrb
   * @param color an Color
   * @throws ConfigurationException for some errors
   */
  public ChangeColor(AmbientOrb orb, String color) throws ConfigurationException {
    this.orb = orb;
    this.color = Color.getEnumValue(color);
    if (this.color == Color.Unsupported) {
      throw new ConfigurationException("Color " + color + " is not supported by AmbientOrb.");
    }
  }

  /**
   * Change the Orb's animation according to the data within this object.
   */
  public void act() {
    System.out.println("Change AmbientOrb's Color to " + color);
    orb.setColor(this.color);
    orb.updateState();
  }

  /**
   * @return the AmbientOrb
   */
  public AmbientOrb getAmbientOrb() {
    return this.orb;
  }

  /**
   * @return the Color
   */
  public Color getColor() {
    return this.color;
  }
}
